from django.shortcuts import render
from django.views import View
from django.http import HttpResponse
from django.utils.decorators import method_decorator
# Create your views here.

def templates_demo(request):
    #模板的使用

    context = {
        'name': '小姐姐',
        'alist': [2,4,5,2,3],
        'adict': {'age': 30}
    }
    #要传到模板文件中渲染的数据必须是以字典的格式传入
    return render(request, 'index.html', context=context)


def my_decorator(func_view):
    def wrapper(request, *args, **kwargs):
        print("装饰器被调用了")
        return func_view(request, *args, **kwargs)

    return wrapper

# @method_decorator(my_decorator, name='get')
class DemoView(View):
    """类视图"""
    #类视图定义的方法必须是请求方法名字小写
    # @method_decorator(my_decorator)
    def get(self, request):

        return HttpResponse('get请求业务逻辑')

    @method_decorator(my_decorator)
    def post(self, request):
        a = request.POST.get('你')
        b = request.POST.get('ww')
        print(a)
        print(b)
        # list = request.POST.getlist()
        # print(list)
        return HttpResponse('post请求业务逻辑')



